package com.lfy.config;

import com.lfy.utils.MinioUtil;
import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


import javax.annotation.Resource;

/**
 * @author lvfeiyang
 */
@EnableConfigurationProperties(MinioConfig.class)
@Configuration
@ConditionalOnProperty(prefix = "lfy.disk", name = "type", havingValue = "minio", matchIfMissing = true)
public class MinioClientConfig {
    @Resource
    private MinioConfig minioConfig;
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(minioConfig.getEndpoint())
                .credentials(minioConfig.getAccessKey(), minioConfig.getSecretKey())
                .build();
    }
    @Bean
    public MinioUtil minioUtil( ) {
        return new MinioUtil();
    }
}